﻿namespace ChumChase
{
    using System.Windows;
    using Caliburn.Actions;
    using Caliburn.Commands;
    using Caliburn.Core;
    using Caliburn.RoutedUIMessaging;
    using Infrastructure;
    using Model;
    using Presenters;
    using Services;

    public partial class App : Application
    {
        private readonly SimpleContainer _container;

        public App()
        {
            _container = new SimpleContainer();

            CaliburnApplication
                .ConfigureCore(ConfigureContainer())
                .WithRoutedUIMessaging()
                .WithCommands()
                .WithActions()
                .StartApplication();
        }


        protected override void OnStartup(StartupEventArgs e)
        {
            MvpConfiguration.InferViewsFromPresenters(Resources);

            base.OnStartup(e);

            _container.GetInstance<IApplicationModel>().Start();
        }

        private SimpleContainer ConfigureContainer()
        {
            _container.RegisterSingleton<IFeedProviderCatalog, FeedProviderCatalog>();
            _container.RegisterSingleton<IApplicationModel, ApplicationModel>();
            _container.RegisterSingleton<ISettingsPresenter, SettingsPresenter>();
            _container.RegisterSingleton<ILocalStorage, LocalStorage>();
            _container.RegisterSingleton<IScheduler, Scheduler>();
            _container.RegisterSingleton<IUserSettings, UserSettings>();

            return _container;
        }
    }
}